package com.demo.example;

import io.micrometer.core.instrument.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gy
 * @date 2022/12/1
 */
public class SqlAwesome {
    public static void main(String[] args) {
        // 进行汇总删除无关的列提升性能
        String hjSql = "";
        String trainAddress = "";
        String finalHjSql = hjSql
                .replace("DATE_FORMAT(ptc.start_training_date,'%Y') trainingYear,","")
                .replace(" DATE_FORMAT(ptc.start_training_date,'%Y-%m-%d') trainingStartDate,DATE_FORMAT(ptc.end_training_date,'%Y-%m-%d') trainingEndDate, ","")
                .replace("headteacher.teacher, ","")
                .replace(" case when pctt.name is null then '专业技能提升班' when pctt.name = '地协合作班' then '专业技能提升班' else pctt.name end classType, ","")
                .replace(" ptc.ext4 as otherClassType,case when pctt.name = '地协合作班' then '是' else '否' end as isDX, ptc.name as className, ","")
                .replace("pr.name as trainAddress,", "");
        // 多表联查，性能极低；若未使用该条件进行查询；删除多余的连表查询,提升效率
        // 注意：由于性能极低，explain 发现没走索引，是由于 走索引还不如不走
        // 若使用该条件，就不能删除，但是由于缩小了查询范围，会走索引，仍然会提升查询效率
        if (StringUtils.isBlank(trainAddress)){
            finalHjSql = finalHjSql
                    .replace(" left join pr_class_meeting_hotel pcmh on pcmh.fk_class_id = ptc.id ", "")
                    .replace(" left join pe_meeting_hotel pmh on pcmh.fk_meeting_hotel_id = pmh.id ", "")
                    .replace(" left join pe_region pr on pmh.fk_city_id = pr.id ", "");
        }


        List<String> roles = new ArrayList<>();
        roles.add("aaa");
        roles.add("bbbfdsa ");
        System.out.println(roles);
    }
}
